package zunge.lbe.datacollect;

import java.util.ArrayList;
import java.util.List;

import zunge.tools.DbConn;

public class M_DataCollect {
	public static void main(String args[]){
		try{
			
//			DbConn connDataMayCreate = new DbConn("127.0.0.1", "lbe_data_may","root","sergeypk428571");
//			BlobParser.createTables(connDataMayCreate);
//			connDataMayCreate.close();
//			
//			List<ParseBlobsThread> threads = new ArrayList<ParseBlobsThread>();
//			
//			//for(int dateInt = 99990001;dateInt <= 99990002;++dateInt){
//			for(int dateInt = 20130501;dateInt <= 20130510;++dateInt){
//				threads.add(new ParseBlobsThread(dateInt));
//			}
//			for(ParseBlobsThread thread:threads){thread.start(ParseBlobsThread.FLAG_DICT, false);}
//			for(ParseBlobsThread thread:threads){thread.start(ParseBlobsThread.FLAG_DETAIL, true);}
//			for(ParseBlobsThread thread:threads){thread.thread.join();}
//			
//			
//			DbConn connDataMay = new DbConn("127.0.0.1", "lbe_data_may","root","sergeypk428571");
//			DbConn connDataMayOut = new DbConn("127.0.0.1", "lbe_data_may","root","sergeypk428571");
//			StatUAP.stat(connDataMay, connDataMayOut);
//			connDataMay.close();
//			connDataMayOut.close();
			
			DbConn connDataMay = new DbConn("127.0.0.1", "lbe_data_may","root","sergeypk428571");
			StatUAP.filtering(connDataMay);
			connDataMay.close();
			
		}catch(Exception e){e.printStackTrace();}
	}
	
	static class ParseBlobsThread implements Runnable{
		public int dateInt;
		public int flag;
		public static final int FLAG_DICT = 0;
		public static final int FLAG_DETAIL = 1;
		public Thread thread;
		
		public ParseBlobsThread(int dateInt){this.dateInt = dateInt;}
		public void start(int flag, boolean fork){
			this.flag = flag;
			thread = new Thread(this, "ParseBlobsThread "+dateInt);
			
			if(fork){thread.start();}
			else{thread.run();}
		}
		@Override
		public void run(){
			try{
				DbConn connDump = new DbConn("127.0.0.1", "lbe_dump","root","sergeypk428571");
				DbConn connDataMayDict = new DbConn("127.0.0.1", "lbe_data_may","root","sergeypk428571");
				DbConn connDataMay = new DbConn("127.0.0.1", "lbe_data_may","root","sergeypk428571");
				
				switch(flag){
				case FLAG_DICT: BlobParser.parseBlobsDict(connDump, dateInt, connDataMay); break;
				case FLAG_DETAIL: BlobParser.parseBlobsDetail(connDump, dateInt, connDataMayDict, connDataMay); break;
				}

				connDump.close();
				connDataMayDict.close();
				connDataMay.close();
			}catch(Exception e){e.printStackTrace();}
		}
		
	}
}
